//
//  CCParyCell.m
//  Party
//
//  Created by its on 15/3/11.
//  Copyright (c) 2015年 coco. All rights reserved.
//

#import "CCPartyCell.h"
#import <SDWebImage/UIImageView+WebCache.h>
#import "CCPartyCellViewModel.h"
#import "CCDevice.h"
#import <QuartzCore/QuartzCore.h>
#import "SDPhotoBrowser.h"
@interface CCPartyCell()

@property (nonatomic, weak) CCPartyCellViewModel *model;
@end
@implementation CCPartyCell

- (void)awakeFromNib {
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  [super setSelected:selected animated:animated];
}

- (void)bindViewModel:(CCPartyCellViewModel *)viewModel {
    [self.bgImageView sd_setImageWithURL:viewModel.bgURL];
    [self.headImageView sd_setImageWithURL:viewModel.headURL];
    self.nameLabel.attributedText = viewModel.name;
    self.heartImageView.image = viewModel.heardImage;
    self.heartLabel.attributedText = viewModel.heard;
    self.addressIcon.image = viewModel.addressImage;
    self.addressLabel.attributedText = viewModel.address;
    self.timeIcon.image = viewModel.timeImage;
    self.timeLabel.attributedText = viewModel.time;
    self.peopleIcon.image = viewModel.peopleImage;
    self.peopleLabel.attributedText = viewModel.people;
    self.moneyIcon.image = viewModel.moneyImage;
    self.moneyLabel.attributedText = viewModel.money;

}

- (id)initWithStyle:(UITableViewCellStyle)style
    reuseIdentifier:(NSString *)reuseIdentifier {
  self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  if (self) {
      [self setupUI];
      [self viewWithCSS];
  }
  return self;
}

- (void) setupUI {
    VIEW(
         self.bgImageView = [UIImageView new];
         [self.contentView addSubview:self.bgImageView];
    )
    VIEW(
         self.titleLabel = [UILabel new];
         [self.titleLabel sizeToFit];
         [self.contentView addSubview: self.titleLabel];
    )
    VIEW(
         self.peopleIcon = [UIImageView new];
         self.peopleLabel = [UILabel new];
         [self.contentView addSubview:self.peopleIcon];
         [self.contentView addSubview: self.peopleLabel];
    )
    
    VIEW(
         self.moneyIcon = [UIImageView new];
         self.moneyLabel = [UILabel new];
         [self.contentView addSubview: self.moneyIcon];
         [self.contentView addSubview: self.moneyLabel];
    )
    
    VIEW(
         self.addressIcon = [UIImageView new];
         self.addressLabel = [UILabel new];
         [self.contentView addSubview:self.addressIcon];
         [self.contentView addSubview: self.addressLabel];
    )
    
    VIEW(
         self.timeIcon = [UIImageView new];
         self.timeLabel = [UILabel new];
         [self.contentView addSubview: self.timeIcon];
         [self.contentView addSubview: self.timeLabel];
    )
    VIEW(
         self.headImageView = [UIImageView new];
         self.nameLabel = [UILabel new];
         [self.contentView addSubview: self.headImageView];
         [self.contentView addSubview: self.nameLabel];
    )
    
    VIEW(
         self.heartImageView = [UIImageView new];
         self.heartLabel = [UILabel new];
         [self.contentView addSubview: self.heartImageView];
         [self.contentView addSubview: self.heartLabel];
    )
    
}

- (void)viewWithCSS {
  @weakify(self);
  [self.bgImageView mas_updateConstraints:^(MASConstraintMaker *make) {
    make.left.mas_equalTo(0);
    make.top.mas_equalTo(0);
    make.size.mas_equalTo(CGSizeMake(DEVICEWIDTH, DEVICEWIDTH * 0.8));
  }];

  [self.contentView mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.size.equalTo(self.bgImageView);
  }];

  [self.headImageView mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.top.equalTo(self.contentView).offset(5);
    make.leading.equalTo(self.contentView).offset(5);
    make.size.mas_equalTo(CGSizeMake(35, 35));
  }];
  [self.nameLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.headImageView.mas_right).offset(2);
    make.centerY.equalTo(self.headImageView);
    make.right.equalTo(self.heartImageView.mas_left).offset(-2);
  }];

  [self.heartImageView mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.right.equalTo(self.contentView).offset(-5);
    make.top.equalTo(self.contentView).offset(-5);
    make.size.mas_equalTo(CGSizeMake(65, 65));
  }];
  [self.heartLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.bottom.equalTo(self.heartImageView);
    make.centerY.equalTo(self.heartImageView);
    make.centerX.equalTo(self.heartImageView);
  }];

  [self.addressIcon mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.contentView).offset(5);
    make.bottom.equalTo(self.contentView).offset(-5);
    make.size.mas_equalTo(CGSizeMake(13, 13));
  }];
  [self.addressLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.addressIcon.mas_right).offset(2);
    make.top.equalTo(self.addressIcon);
    make.bottom.equalTo(self.addressIcon);
    make.right.equalTo(self.timeIcon.mas_left).offset(2);
  }];

  [self.timeIcon mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.contentView).offset(DEVICEWIDTH / 2);
    make.bottom.equalTo(self.contentView).offset(-5);
    make.size.mas_equalTo(CGSizeMake(13, 13));
  }];
  [self.timeLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.timeIcon.mas_right).offset(2);
    make.top.equalTo(self.timeIcon);
    make.bottom.equalTo(self.timeIcon);
    make.right.equalTo(self.contentView).offset(-2);
  }];

  [self.peopleIcon mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.contentView).offset(5);
    make.bottom.equalTo(self.addressIcon.mas_top).offset(-5);
    make.size.mas_equalTo(CGSizeMake(13, 13));
  }];
  [self.peopleLabel mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.peopleIcon.mas_right).offset(2);
    make.top.equalTo(self.peopleIcon);
    make.bottom.equalTo(self.peopleIcon);
    make.right.equalTo(self.moneyIcon).offset(-2);
  }];

  [self.moneyIcon mas_updateConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.contentView).offset(DEVICEWIDTH / 2);
    make.bottom.equalTo(self.timeIcon.mas_top).offset(-5);
    make.size.mas_equalTo(CGSizeMake(13, 13));
  }];
  [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.moneyIcon.mas_right).offset(2);
    make.top.equalTo(self.moneyIcon);
    make.bottom.equalTo(self.moneyIcon);
    make.right.equalTo(self.contentView).offset(-2);
  }];

  [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
    @strongify(self);
    make.left.equalTo(self.contentView).offset(5);
    make.bottom.equalTo(self.moneyIcon.mas_top).offset(-5);
  }];
}

@end
